# Created by 黄景涛
# DATE: 2025/4/16

import random

from faker import Faker
from pypinyin import lazy_pinyin

from request_task import post_task, get_task
from async_run import async_main

fk = Faker(locale='zh_CN')


def random_chars(counts, char_type=None):
    char_pools = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789"
    if char_type == 'digit':
        char_pools = "".join(c for c in char_pools if c.isdigit())
    elif char_type == 'alpha':
        char_pools = "".join(c for c in char_pools if c.isalpha())
    return ''.join(random.choices(char_pools, k=counts))


def user_params(i):
    # 中文名：随机姓名+后缀
    display_name = fk.name()
    # 姓名拼音+后缀
    pinyin = ''.join(lazy_pinyin(display_name))
    mp = {
        # "departments": [[4], [6], [7], [5]],    # azure-bkee5.canwaysoft.com
        "departments": [[8]],  # azure-bkee5.canwaysoft.com
        "username": [pinyin],
        "display_name": [display_name],
        "email": [fk.free_email()],  # 邮箱
        "telephone": [fk.phone_number()],  # 手机号
        "wx_userid": ["", "weixin" + random_chars(10)],
        "qq": [random_chars(8, 'digit')],
        "status": ["NORMAL"],  # 账户状态
        "staff_status": ["IN"],  # 在职状态
        # "status": ["NORMAL", "LOCKED", "DELETED", "DISABLED", "EXPIRED"],     # 账户状态
        # "staff_status": ["IN", "OUT"],   # 在职状态

    }

    data = {
        "category_id": 1,
        "leader": [],
        "departments": [4],
        "password_valid_days": -1,
        "username": "spra",
        "display_name": "审批人A",
        "email": "4865@qq.com",
        "telephone": "15678412031",
        "iso_code": "cn",
        "status": "NORMAL",
        "staff_status": "IN",
        "position": "0",
        "wx_userid": "",
        "qq": "",
        "account_expiration_date": "",
        # "fgjh": random_chars(10)

    }

    for k, v in data.items():
        if k in mp:
            data[k] = random.choice(mp[k])

    return data


if __name__ == '__main__':
    config = {"thread_count": 10, "task_count": 12}
    # _url = "http://bkuser.azure-bkee5.canwaysoft.com/api/v1/web/profiles/"
    # _url = "https://bkuser.dev-x86.goldendb5.com/api/v1/web/profiles/"
    _url = "https://bkuser.dev-arm.cwbk5.com/api/v1/web/profiles/"

    headers = {"Content-Type": "application/json",
               "X-Csrftoken": "yFNbRQ3lsqxtg9SwepkNRw8tvPzt10C4",
               "Cookie": "bk_token=bkcrypt%24gAAAAABoKtzKpMlx_RB6ngyOpSn9NTfeLbEynj8Oe06X3oVy43rhd-bzx6XMiyP-4Ah8et38f6UJQBguc7IGtTFG-J9pWDBpiB4CLUypzPkDcP8lmn0GoT0%3D; blueking_language=zh-cn; bkuser_csrftoken=yFNbRQ3lsqxtg9SwepkNRw8tvPzt10C4; sessionid=3t5w1qj72277i3nvm3kx4nzoz110vk79"
               }
    async_main(config, post_task, user_params, _url, headers)
